package com.briup.srms.sms.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.briup.srms.sms.bean.Client;
import com.briup.srms.sms.dao.ClientMapper;
import com.briup.srms.sms.dao.extend.ClientExtendMapper;
import com.briup.srms.sms.service.IClientService;
import com.jacky.base.utils.CustomerException;
import com.jacky.base.utils.PageVM;

@Service
public class ClientServiceImpl implements IClientService {
	
	@Autowired
	private ClientMapper clientMapper;
	@Autowired
	private ClientExtendMapper clientExtendMapper;
	
	@Override
	public PageVM<Client> pageQuery(int page, int pageSize,Long[] channelIds,String realname) {
		List<Client> list = clientExtendMapper.query(page, pageSize,channelIds,realname);
		long total = clientExtendMapper.count(channelIds,realname);
		return new PageVM<>(page, pageSize, total, list);
	}
	@Override
	public void saveOrUpdate(Client client) {
		if(client.getId() == null) {
			clientMapper.insert(client);
		} else {
			clientMapper.updateByPrimaryKey(client);
		}
		
	}
	@Override
	public void deleteById(long id) {
		Client dict = clientMapper.selectByPrimaryKey(id);
		if(dict == null) {
			throw new CustomerException("要删除的数据不存在");
		}
		clientMapper.deleteByPrimaryKey(id);
		
	}
}
